Kanzi 4.0.0-beta2
kanzi::VectorMap< TKey, TValue > Class Template Reference

VectorMap stores key-value pairs in an unordered vector and provides a simple find interface. More...

#include <kanzi/core/util/vector_map.hpp>

Public Member Functions

auto && at (size_t index)
 Gets the item at a given integral index.
 
auto && at (size_t index) const
 
auto begin () const noexcept
 
auto begin () noexcept
 Gets the begin iterator of the VectorMap.
 
size_t capacity () const noexcept
 Gets the current capacity of the underlying vector.
 
void clear () noexcept
 Clear the contents of the VectorMap.
 
template<typename TComparableKey >
bool contains (const TComparableKey &searchKey) const
 Tests if an element is contained in the VectorMap.
 
auto data ()
 Gets direct access to the underlying array.
 
auto data () const
 
template<typename... TArgs>
autoemplace (TKey key, TArgs &&... args)
 Emplace a new element in the VectorMap.
 
auto empty () const noexcept
 Test if the VectorMap is empty.
 
auto end () const noexcept
 
auto end () noexcept
 Gets the begin iterator of the VectorMap.
 
size_t erase (const TKey &key)
 Removes the element found by the given key.
 
iterator erase (iterator pos)
 Removes the element at pos.
 
template<typename TComparableKey >
auto find (const TComparableKey &searchKey)
 Find an element in the VectorMap.
 
template<typename TComparableKey >
auto find (const TComparableKey &searchKey) const
 Find an element in the VectorMap.
 
template<typename TComparableKey >
auto && operator[] (const TComparableKey &searchKey)
 Find or Insert the given key.
 
void reserve (size_t newCapacity)
 Reserve a capacity in the VectorMap.
 
auto size () const noexcept
 Gets the size of the VectorMap.
 

Detailed Description

template<typename TKey, typename TValue>
class kanzi::VectorMap< TKey, TValue >

VectorMap stores key-value pairs in an unordered vector and provides a simple find interface.

Intended for small lists, There is no checking for duplicate keys.

Since
Kanzi 4.0.0

Member Function Documentation

◆ find() [1/2]

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::find ( const TComparableKey & searchKey)
inline

Find an element in the VectorMap.

Uses heterogeneous lookup on the search key.

Parameters
searchKeyThe search key.
Returns
iterator of the found element.

◆ find() [2/2]

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::find ( const TComparableKey & searchKey) const
inline

Find an element in the VectorMap.

Uses heterogeneous lookup on the search key.

Parameters
searchKeyThe search key.
Returns
iterator of the found element.

◆ emplace()

template<typename TKey , typename TValue >
template<typename... TArgs>
auto & kanzi::VectorMap< TKey, TValue >::emplace ( TKey key,
TArgs &&... args )
inline

Emplace a new element in the VectorMap.

Parameters
keyThe key.
argsThe arguments used for value construction
Returns
iterator of the newly inserted element

◆ contains()

template<typename TKey , typename TValue >
bool kanzi::VectorMap< TKey, TValue >::contains ( const TComparableKey & searchKey) const
inline

Tests if an element is contained in the VectorMap.

Uses heterogeneous lookup on the search key.

Parameters
searchKeyThe search key.
Returns
true if the key is within the VectorMap.

◆ operator[]()

Find or Insert the given key.

The Value must be default constructible. Can use heterogeneous lookup on the search key, but the search key must be able to also construct a key.

Parameters
searchKeyThe key to find or insert.
Returns
iterator of the found element.

◆ clear()

template<typename TKey , typename TValue >
void kanzi::VectorMap< TKey, TValue >::clear ( )
inlinenoexcept

Clear the contents of the VectorMap.

◆ empty()

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::empty ( ) const
inlinenoexcept

Test if the VectorMap is empty.

Returns
true if the VectorMap is empty.

◆ size()

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::size ( ) const
inlinenoexcept

Gets the size of the VectorMap.

Returns
The number of elements in the VectorMap.

◆ begin() [1/2]

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::begin ( )
inlinenoexcept

Gets the begin iterator of the VectorMap.

Returns
The begin iterator.

◆ begin() [2/2]

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::begin ( ) const
inlinenoexcept

◆ end() [1/2]

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::end ( )
inlinenoexcept

Gets the begin iterator of the VectorMap.

Returns
The begin iterator.

◆ end() [2/2]

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::end ( ) const
inlinenoexcept

◆ data() [1/2]

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::data ( )
inline

Gets direct access to the underlying array.

Returns
A pointer to the VectorMap data.

◆ data() [2/2]

template<typename TKey , typename TValue >
auto kanzi::VectorMap< TKey, TValue >::data ( ) const
inline

◆ reserve()

template<typename TKey , typename TValue >
void kanzi::VectorMap< TKey, TValue >::reserve ( size_t newCapacity)
inline

Reserve a capacity in the VectorMap.

Parameters
newCapacityThe new capacity.

◆ capacity()

template<typename TKey , typename TValue >
size_t kanzi::VectorMap< TKey, TValue >::capacity ( ) const
inlinenoexcept

Gets the current capacity of the underlying vector.

Returns
The container capacity.

◆ at() [1/2]

template<typename TKey , typename TValue >
auto && kanzi::VectorMap< TKey, TValue >::at ( size_t index)
inline

Gets the item at a given integral index.

Parameters
indexThe index to retreive.
Returns
The item at the given index.

◆ at() [2/2]

template<typename TKey , typename TValue >
auto && kanzi::VectorMap< TKey, TValue >::at ( size_t index) const
inline

◆ erase() [1/2]

template<typename TKey , typename TValue >
iterator kanzi::VectorMap< TKey, TValue >::erase ( iterator pos)
inline

Removes the element at pos.

Parameters
posThe position to remove.
Returns
The iterator following the element that was removed.

◆ erase() [2/2]

template<typename TKey , typename TValue >
size_t kanzi::VectorMap< TKey, TValue >::erase ( const TKey & key)
inline

Removes the element found by the given key.

This does not use heterogenous lookup.

Parameters
keyThe key to remove.
Returns
The number of elements removed, 0 or 1;

The documentation for this class was generated from the following file: